package com.njym.java.security.app.rest;

import com.njym.java.security.app.biz.FamilyConOrderBiz;
import com.njym.java.security.app.entity.FamilyConOrder;
import com.njym.java.security.app.entity.PhotoAlbumVo;
import com.njym.java.security.common.msg.ObjectRestResponse;
import com.njym.java.security.common.rest.BaseController;
import com.njym.java.security.common.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("familyConOrder")
public class FamilyConOrderController extends BaseController<FamilyConOrderBiz,FamilyConOrder> {
    @Autowired
    private FamilyConOrderBiz familyConOrderBiz;


    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ResponseBody
    public Object list(@RequestParam String userId){
        if (!userId.equals("undefined")) {
            List<FamilyConOrder> list = familyConOrderBiz.selectMyConsults(Integer.parseInt(userId));
            Map<String, Object> data = new HashMap<>(1);
            data.put("list", list);
            return new ObjectRestResponse<PhotoAlbumVo>().rel(true).data(data);
        } else {
            return ResponseUtil.fail(40301, "错误！");
        }
    }


    @RequestMapping(value = "/addConOrder",method = RequestMethod.GET)
    @ResponseBody
    public Object addConOrder(@RequestParam String userId, @RequestParam String conId, @RequestParam String exigency,
                                             @RequestParam String queDescribe, @RequestParam String mobile, @RequestParam String acceptAnswerTime) {
        if (!userId.equals("undefined") && !conId.equals("undefined") && !exigency.equals("undefined")) {
            FamilyConOrder familyConOrder = new FamilyConOrder();
            familyConOrder.setUserId(Integer.parseInt(userId));
            familyConOrder.setConId(Integer.parseInt(conId));
            familyConOrder.setExigency(Integer.parseInt(exigency));
            familyConOrder.setMobile(mobile);
            familyConOrder.setAcceptAnswerTime(acceptAnswerTime);
            familyConOrder.setQueDescribe(queDescribe);
            familyConOrder.setDeleted(0);
            familyConOrder.setStatus(0);
            familyConOrder.setAttr1(0);
            baseBiz.insertSelective(familyConOrder);
            return new ObjectRestResponse<PhotoAlbumVo>().rel(true);
        } else {
            return ResponseUtil.fail(40301, "错误！");
        }

    }

}